<template>
  <h1>完整对象：{{ obj }}</h1>
  <button @click="obj.age++">点击年龄+1</button>
</template>

<script>
import { reactive, watch } from 'vue';
export default {
  setup() {
    const obj = reactive({
      name: '小白兔',
      age: 20,
      cp: {
        name: '陈嘉丽',
        age: 20,
      },
    });

    // 侦听器
    watch(obj, () => {
      console.log('obj发生改变啦');
      localStorage.setItem('obj', JSON.stringify(obj));
    });

    return { obj };
  },
};
</script>
